package moxl.parser.assemblers.doctypedecl;

import moxl.parser.ParserException;
import moxl.parser.assemblers.AbstractTokenFedMarkupAssembler;
import moxl.parser.assemblers.AssemblerException;
import moxl.tokenizer.TokenStream;
import moxl.tokenizer.TokenizerException;
import moxl.tokenizer.xml.XmlTokenType;

public class DocumentTypeDeclarationAssembler extends
        AbstractTokenFedMarkupAssembler<DocumentTypeDeclarationAssemblerState, DocumentTypeDeclarationAssemblerContext>
{
	@Override
	protected DocumentTypeDeclarationAssemblerContext createAssemblerContext(TokenStream tstream) throws ParserException, TokenizerException
	{
		return new DocumentTypeDeclarationAssemblerContext(tstream);
	}

	@Override
	protected void handleInput(XmlTokenType type, DocumentTypeDeclarationAssemblerContext ctx) throws ParserException, TokenizerException
	{
		DocumentTypeDeclarationStateDelegateBase delegate = ctx.getState().getDelegate();
		switch (type)
		{
		case OPEN_CHEVRON_EXCLAMATION_MARK:
			delegate.acceptOpenChevronExclamationMark(ctx);
			break;

		case NAME:
			delegate.acceptName(ctx);
			break;
			
		case SPACE:
			delegate.acceptSpace(ctx);
			break;

		case WHITESPACE:
			delegate.acceptWhitespace(ctx);
			break;
			
		case DOCTYPE_BODY:
			delegate.acceptDoctypeBody(ctx);
			break;

		case CLOSE_CHEVRON:
			delegate.acceptCloseChevron(ctx);
			break;
			
		default:
			throw new AssemblerException("Parser cannot handle token: " + ctx.getToken(), ctx.getLocation());
		}
	}
}
